package com.qf.sy2103.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.sy2103.ssm.dao.KehuDao;
import com.qf.sy2103.ssm.entity.Kehu;
import com.qf.sy2103.ssm.entity.User;
import com.qf.sy2103.ssm.service.KehuService;
import com.qf.sy2103.ssm.vo.PageVo;
import com.qf.sy2103.ssm.vo.TableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class KehuServiceImpl implements KehuService {
    @Autowired
    private KehuDao kehuDao;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int add(Kehu kehu) {
        return kehuDao.insert(kehu);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updata(Kehu kehu) {
        return kehuDao.update(kehu);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int del(Integer[] id) {
        return kehuDao.delete(id);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public TableVo<Kehu> all(PageVo pageVo, Kehu kehu) {
        PageHelper.startPage(pageVo.getPage(),pageVo.getLimit());
        List<Kehu> kehus = kehuDao.selectall(kehu);
        PageInfo<Kehu> pageInfo=new PageInfo<>(kehus);
        return new TableVo<Kehu>(0,"ok",pageInfo.getTotal(),kehus);

    }

    @Override
    public Kehu sname(Kehu kehu) {
        return kehuDao.selectname(kehu);
    }
}
